package com.hrhx.springboot.web;

import com.hrhx.duhongming.bean.EchartsConfig;
import com.hrhx.duhongming.core.HighChartsCore;
import com.hrhx.springboot.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * 
 * @author duhongming
 *
 */
@Controller
@RequestMapping("/highcharts")
public class HighChartsDemo {
	
	@Autowired
	private DataService dataService;
	
	/**
	 * 演示页面
	 * @return
	 */
	@RequestMapping(value = "demo", method = RequestMethod.GET)
	public String echartsDemo(String theme,ModelMap modelMap){
		String themeUrl = "/highcharts/code/themes/"+theme+".js";
		modelMap.put("theme", theme);
		modelMap.put("themeUrl", themeUrl);
		return "/Highcharts";
	}
	
	/**
	 * 3D条形图
	 * @param echartsConfig
	 * @return
	 */
	@RequestMapping(value = "bar3d", method = RequestMethod.POST,
			consumes = "application/json",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody String bar3d(@RequestBody EchartsConfig echartsConfig){
		return HighChartsCore.getInstance().adapterBar3D(echartsConfig, dataService.getWeatherData()).toString();
	}
	
	/**
	 * 3D饼状图
	 * @param echartsConfig
	 * @return
	 */
	@RequestMapping(value = "pie3d", method = RequestMethod.POST,
			consumes = "application/json",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody String pie3d(@RequestBody EchartsConfig echartsConfig){
		return HighChartsCore.getInstance().adapterPie3D(echartsConfig, dataService.getPieData()).toString();
	}
	
}
